﻿using S7CommPlusDriver.ClientApi;
using System.Linq;
using System.Reflection;

namespace S7CommPlusDriverCore.Extension
{

    public interface ITagAware
    {
        public TagsManager TagsManager { get; set; }

        public void Write<T>(string name, T value)
        {
            var monitoredItemAttribute = this.GetType().GetProperty(name).GetCustomAttribute<MonitoredItemAttribute>();

            var plcTag = TagsManager.TempPlcTags.FirstOrDefault(x => x.Name == monitoredItemAttribute.TagName);

            var tempTag = Helper.CreatePlcTag(plcTag.Name, plcTag.Address, plcTag.Datatype);

            tempTag.SetValue(value);

            TagsManager.WritePlcTags.Add(tempTag);
        }
    }

}
